// attendWrite.js
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    leaveMsg: {
      placeholderTxt: "请假缘由",
      gtBtnTxt: "确定"
    },
    why: "",
    rowId : 0,
    studentId :0,
    employeesId :0,
    classSonId :0,
    teamId :0,
    status :  1
  },
 
  formSubmit: function(e){
    var that = this;
    var why = e.detail.value.textarea;
    console.log(e.detail.value.textarea);
    wx.request({
      url: app.globalData.http + "signIn.do",
      data: {
          why: why,
          rowId: parseInt(that.data.rowId),
          studentId: "",
          employeesId: "",
          classSonId: parseInt(that.data.classSonId),
          teamId: parseInt(that.data.teamId),
          status: "1",
          busId: parseInt(wx.getStorageSync("busId")),
          employeesId: parseInt(wx.getStorageSync("employeesId")),
          schoolId: parseInt(wx.getStorageSync("schoolId"))
       },
      header: {
        'content-type': 'application/json'
      },
      success: function(res){
       console.log("请假成功返回数据==",res);
        var code = res.data.code;
        if(code == 100){
          if(why == "" || why == null){
             wx.showToast({
              title: '不能为空',
              image: "/img/ico/fail.png",
              duration: 2000  
            });
            console.log("提交内容为空==")
            return false;
          }else{
            wx.redirectTo({
              url: "/pages/attendSuccess/attendSuccess"
            })
          }
        }else{
          wx.showToast({
            title: '发布失败',
            image: "/img/ico/fail.png",
            duration: 2000  
          });
          return
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("教师请假options==",options);
    var that = this;
    that.setData({
      rowId: options.rowId,
      employeesId: options.employeesId,
      classSonId: options.classSonId,
      teamId: options.teamId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})